﻿@using Entidades.Sistema.Venta
@using Entidades.Sistema.Base
@using System.Collections.ObjectModel;

@model Cliente
@{
    Html.EnableClientValidation(true);
    Html.EnableUnobtrusiveJavaScript(true);
    ReadOnlyCollection<TipoCliente> _tipoClienteList = (ReadOnlyCollection<TipoCliente>)ViewBag.TipoClientes;
    ReadOnlyCollection<CondicionIva> _condicionIvaList = (ReadOnlyCollection<CondicionIva>)ViewBag.CondicionIva;
    ReadOnlyCollection<Barrio> _barrioList = (ReadOnlyCollection<Barrio>)ViewBag.Barrio;
    ReadOnlyCollection<Localidad> _localidadList = (ReadOnlyCollection<Localidad>)ViewBag.Localidad;
    ReadOnlyCollection<Provincia> _provinciaList = (ReadOnlyCollection<Provincia>)ViewBag.Provincia;
}

<script type="text/javascript">
//<![CDATA[
    function OnNameValidation(s, e) {
        debugger;
        if (e.value == null)
            e.isValid = false;
        var name = String(e.value);
        if (name == "")
            e.isValid = false;
        if (name.length > 50) {
            e.isValid = false;
            e.errorText = "Must be under 50 characters";
        }
    }

    function OnAgeValidation(s, e) {
        if (e.value == null || e.value == "")
            return;
        var age = Number(e.value);
        if (isNaN(age) || age < 18 || age > 100)
            e.isValid = false;
    }
// ]]> 
</script>

@using (Html.BeginForm("EditClientesUpdatePartial", "Cliente", FormMethod.Post, new { @class = "edit_form"}))
{
    
    @Html.Hidden("IdCliente")
    <div class="line">
        @Html.DevExpress().Label(
            settings => {
                settings.ControlStyle.CssClass = "label";
                settings.Text = "Nombre Cliente:";
                settings.AssociatedControlName = "Nombre";
            }
        ).GetHtml()
        @Html.DevExpress().TextBox(
            settings => {
                settings.Name = "Nombre";
                settings.ControlStyle.CssClass = "editor";
                settings.ShowModelErrors = true;
                settings.Properties.ValidationSettings.ErrorDisplayMode = ErrorDisplayMode.ImageWithText;
                settings.Properties.ClientSideEvents.Validation = "OnNameValidation";
            }
        ).Bind(Model.Nombre).GetHtml()
        
    </div>
    
    <div class="line">
        @Html.DevExpress().Label(
            settings => {
                settings.ControlStyle.CssClass = "label";
                settings.Text = "Telefono:";
                settings.AssociatedControlName = "Telefono";
            }
        ).GetHtml()
        @Html.DevExpress().TextBox(
            settings => {
                settings.Name = "Telefono";
                settings.ControlStyle.CssClass = "editor";
                settings.Properties.MaskSettings.Mask = "+54 (999) 000-0000";
                settings.Properties.MaskSettings.IncludeLiterals = MaskIncludeLiteralsMode.None;                
            }
        ).Bind(Model.Telefono).GetHtml()
    </div>
    
    <div class="line">
        @Html.DevExpress().Label(
            settings => {
                settings.ControlStyle.CssClass = "label";
                settings.Text = "Fax:";
                settings.AssociatedControlName = "Fax";
            }
        ).GetHtml()
        @Html.DevExpress().TextBox(
            settings => {
                settings.Name = "Fax";
                settings.ControlStyle.CssClass = "editor";
                settings.Properties.MaskSettings.Mask = "+54 (999) 000-0000";
                settings.Properties.MaskSettings.IncludeLiterals = MaskIncludeLiteralsMode.None;
            }
        ).Bind(Model.Fax).GetHtml()
    </div>
    
    <div class="line">
        @Html.DevExpress().Label(
            settings => {
                settings.ControlStyle.CssClass = "label";
                settings.Text = "Email:";
                settings.AssociatedControlName = "Email";
            }
        ).GetHtml()
        @Html.DevExpress().TextBox(
            settings => {
                settings.Name = "Email";
                settings.ControlStyle.CssClass = "editor";
                settings.ShowModelErrors = true;
                settings.Properties.ValidationSettings.ErrorDisplayMode = ErrorDisplayMode.ImageWithText;
            }
        ).Bind(Model.Email).GetHtml()
    </div>
    
    <div class="line">
        @Html.DevExpress().Label(
            settings => {
                settings.ControlStyle.CssClass = "label";
                settings.AssociatedControlName = "TipoCliente.IdTipoCliente";
                settings.Text = "Tipo Cliente:";
            }
        ).GetHtml()
        @Html.DevExpress().ComboBox(
            settings => {
                settings.Name = "IdTipoCliente";
                settings.ControlStyle.CssClass = "editor";
                settings.Properties.TextField = "Nombre";
                settings.Properties.ValueField = "IdTipoCliente";
                settings.Properties.ValueType = typeof(int);
                //settings.Properties.ClientSideEvents.Init = "function(s,e){if(s.GetValue()=='0'){ s.SetValue(null);} }";
                settings.Properties.ValidationSettings.ErrorDisplayMode = ErrorDisplayMode.ImageWithText;
                //settings.Properties.ClientSideEvents.Validation = "OnNameValidation";
            }
        ).BindList(_tipoClienteList).Bind(Model.TipoCliente.IdTipoCliente).GetHtml()
    </div>
    
    <div class="line">
        @Html.DevExpress().Label(
            settings => {
                settings.ControlStyle.CssClass = "label";
                settings.AssociatedControlName = "CondicionIva.IdCondicionIva";
                settings.Text = "Condicion de Iva:";
            }
        ).GetHtml()
        @Html.DevExpress().ComboBox(
            settings => {
                settings.Name = "IdCondicionIva";
                settings.ControlStyle.CssClass = "editor";
                settings.Properties.TextField = "Nombre";
                settings.Properties.ValueField = "IdCondicionIva";
                settings.Properties.ValueType = typeof(int);
                settings.ShowModelErrors = true;
                settings.Properties.ValidationSettings.ErrorDisplayMode = ErrorDisplayMode.ImageWithText;
            }
        ).BindList(_condicionIvaList).Bind(Model.CondicionIva.IdCondicionIva).GetHtml()
    </div>   
    <div class="line">
        @Html.DevExpress().Label(
            settings => {
                settings.ControlStyle.CssClass = "label";
                settings.Text = "Cuit:";
                settings.AssociatedControlName = "Cuit";
            }
        ).GetHtml()
        @Html.DevExpress().TextBox(
            settings => {
                settings.Name = "Cuit";
                settings.ControlStyle.CssClass = "editor";
                settings.Properties.MaskSettings.Mask = "99-99999999-9";
                settings.Properties.MaskSettings.IncludeLiterals = MaskIncludeLiteralsMode.None;
            }
        ).Bind(Model.Cuit).GetHtml()
    </div>
    <div class="line">
        @Html.DevExpress().Label(
            settings => {
                settings.ControlStyle.CssClass = "label";
                settings.AssociatedControlName = "Barrio.Localidad.Provincia.IdProvincia";
                settings.Text = "Provincia:";
            }
        ).GetHtml()
        @Html.DevExpress().ComboBox(
            settings => {
                settings.Name = "Provincia";
                settings.ControlStyle.CssClass = "editor";
                settings.Properties.TextField = "Nombre";
                settings.Properties.ValueField = "IdProvincia";
                settings.Properties.ValueType = typeof(int);
                settings.Properties.CallbackPageSize = 20;
                settings.Properties.ClientSideEvents.SelectedIndexChanged = "function(s, e) { Localidad.PerformCallback(); }";
            }
        ).BindList(_provinciaList).Bind(Model.Barrio.Localidad.Provincia.IdProvincia).GetHtml()
    </div>
    
    
    <div class="line">
        @Html.DevExpress().Label(
            settings => {
                settings.ControlStyle.CssClass = "label";
                settings.AssociatedControlName = "Barrio.Localidad.IdLocalidad";
                settings.Text = "Localidad:";
            }
        ).GetHtml()
        @Html.Partial("ComboBoxLocalidadPartial", Model)
    </div>
    
    
    <div class="line">
        @Html.DevExpress().Label(
            settings => {
                settings.ControlStyle.CssClass = "label";
                settings.AssociatedControlName = "Barrio.IdBarrio";
                settings.Text = "Barrio:";
            }
        ).GetHtml()
        @Html.Partial("ComboBoxBarrioPartial", Model)
        @Html.ValidationMessageFor(model => model.Barrio.IdBarrio, null, new { @class = "validator" })
    </div>
    
    <div class="line">
        @Html.DevExpress().Label(
            settings => {
                settings.ControlStyle.CssClass = "label";
                settings.Text = "Calle:";
                settings.AssociatedControlName = "Calle";
            }
        ).GetHtml()
        @Html.DevExpress().TextBox(
            settings => {
                settings.Name = "Calle";
                settings.ControlStyle.CssClass = "editor";
            }
        ).Bind(Model.Calle).GetHtml()
        @Html.ValidationMessageFor(model => model.Calle, null, new { @class = "validator" })
    </div>
    <div class="line">
        @Html.DevExpress().Label(
            settings => {
                settings.ControlStyle.CssClass = "label";
                settings.Text = "NroCalle:";
                settings.AssociatedControlName = "NroCalle";
            }
        ).GetHtml()
        @Html.DevExpress().SpinEdit(
            settings => {
                settings.Name = "NroCalle";
                settings.ControlStyle.CssClass = "editor";
            }
        ).Bind(Model.NroCalle).GetHtml()
    </div>
    
    <div class="line">
        @Html.DevExpress().Label(
            settings => {
                settings.ControlStyle.CssClass = "label";
                settings.Text = "Departamento:";
                settings.AssociatedControlName = "Departamento";
            }
        ).GetHtml()
        @Html.DevExpress().TextBox(
            settings => {
                settings.Name = "Departamento";
                settings.ControlStyle.CssClass = "editor";
            }
        ).Bind(Model.Departamento).GetHtml()

        

    </div>   
    
    
    <div class="line">
        @Html.DevExpress().Label(
            settings => {
                settings.ControlStyle.CssClass = "label";
            }
        ).GetHtml()
        @Html.DevExpress().Button(
            settings => {
                settings.Name = "btnUpdate1";
                settings.ControlStyle.CssClass = "button";
                settings.Text = "Actualizar";
                settings.UseSubmitBehavior = true;
            }
        ).GetHtml()
        @Html.DevExpress().Button(
            settings => {
                settings.Name = "btnCancel1";
                settings.ControlStyle.CssClass = "button";
                settings.Text = "Cancelar";
                settings.ClientSideEvents.Click = "function(s, e){ document.location='" + DevExpressHelper.GetUrl(new { Controller = "Cliente", Action = "Index" }) + "'; }";
            }
        ).GetHtml()
    </div>
}




